from flask import Flask,request,jsonify
from flask_cors import CORS
from utils.redisconn import r
from utils.jwttoken import myjwt
from views.organization import bp_organization
from views.file import bp_file
from views.user import bp_user
from views.resource import bp_resource
from views.workf import bp_work


# app = Flask(__name__)
def create_app():
    app = Flask(__name__)
    with app.app_context():
        pass
    return app
app = create_app()


app.register_blueprint(bp_organization)
app.register_blueprint(bp_file)
app.register_blueprint(bp_user)
app.register_blueprint(bp_resource)
app.register_blueprint(bp_work)

CORS(app)




# @app.before_request
# def before_request():
#     # 白名单
#     white = ['/login']
#     if request.path not in white:
#         try:
#             token = request.headers['Token']
#             print(token)
#         except:
#             return jsonify({'code':403,'msg':'无权访问'})
#
# #     调用jwt解密token
#         if myjwt.jwt_decode(token) == False:
#             return jsonify({'code':402,'msg':'token不合法'})
#
#     #     权限验证
#         payload = myjwt.jwt_de(token)
#         uid = payload['data']['uid']
#         key = 'serve' + str(uid)
#     #     根据用户id获取接口权限
#         list = r.find_set(key)
#         if request.path not in list:
#             return jsonify({'code':40301,'msg':'无权访问'})





@app.route('/')
def hello_world():
    return 'Hello World!'


if __name__ == '__main__':
    app.run(debug=True)
